package cn.ppms.interceptor;


import cn.ppms.tools.Constants;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Objects;


/**
 *
 * @author Administrator
 */
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 没有登录 就直接打回 到 登录界面
        HttpSession session = request.getSession();
        Object o = session.getAttribute(Constants.USER_SESSION);
        if (Objects.isNull(o)) {
            // 证明 没有登录
            response.sendRedirect(request.getContextPath() + "/login.jsp");
            return false;
        }
        return true;
    }
}
